<template>
  <view class="collect-container">
    <!-- 顶部导航栏 -->
    <view class="nav-bar">
      <view class="left" @tap="goBack">
        <text class="iconfont icon-back"></text>
      </view>
      <view class="title">收藏夹</view>
      <view class="right">
        <text class="iconfont icon-more"></text>
        <text class="iconfont icon-share"></text>
      </view>
    </view>

    <!-- 收藏列表区域 -->
    <scroll-view scroll-y class="collect-list">
      <!-- 收藏夹数量和新建按钮 -->
      <view class="collect-header">
        <text class="count">{{folderList.length}}个收藏夹</text>
        <view class="create-btn" @tap="showCreateDialog">
          <text class="plus">+</text>
          <text>新建收藏夹</text>
        </view>
      </view>

      <!-- 收藏夹列表 -->
      <view class="folder-list">
        <view class="folder-item" 
              v-for="(item, index) in folderList" 
              :key="index"
              @tap="goToDetail(item)">
          <image class="folder-image" :src="item.image" mode="aspectFill"></image>
          <view class="folder-info">
            <text class="folder-title">{{item.title}}</text>
            <text class="folder-count">共{{item.count}}条内容</text>
          </view>
        </view>
      </view>
    </scroll-view>

    <!-- 底部导航栏 -->
    <view class="tab-bar">
      <view class="tab-item" 
            v-for="(tab, index) in tabs" 
            :key="index"
            :class="{active: currentTab === index}"
            @tap="switchTab(index)">
        <image :src="currentTab === index ? tab.activeIcon : tab.icon" 
               mode="aspectFit" 
               class="tab-icon"></image>
        <text class="tab-text">{{tab.text}}</text>
      </view>
    </view>

  </view>
</template>

<script>
export default {
  data() {
    return {
      currentTab: 1,
      newFolderName: '',
      folderList: [
        {
          id: 1,
          title: '默认收藏夹',
          image: '/static/images/folder1.jpg',
          count: 5
        },
        {
          id: 2,
          title: '社会话题',
          image: '/static/images/folder2.jpg',
          count: 3
        },
        {
          id: 3,
          title: '科技事件',
          image: '/static/images/folder3.jpg',
          count: 3
        }
      ],
      tabs: [
        {
          icon: '/static/images/tab-news.png',
          activeIcon: '/static/images/tab-news-active.png',
          text: '角报'
        },
        {
          icon: '/static/images/tab-collect.png',
          activeIcon: '/static/images/tab-collect-active.png',
          text: '态度'
        },
        {
          icon: '/static/images/tab-my.png',
          activeIcon: '/static/images/tab-my-active.png',
          text: '我的'
        }
      ]
    }
  },

  methods: {

    // 切换底部标签
    switchTab(index) {
      if (this.currentTab === index) return
      this.currentTab = index
      const routes = ['/pages/news/news', '/pages/collect/collect', '/pages/wode-guanzhu/wode-guanzhu']
      uni.switchTab({
        url: routes[index]
      })
    },

    // 进入收藏夹详情
    goToDetail(folder) {
      uni.navigateTo({
        url: `/pages/collect/detail?id=${folder.id}&title=${folder.title}`
      })
    },

    // 返回上一页
    goBack() {
      uni.navigateBack()
    }
  }
}
</script>
<style lang="scss">
.collect-container {
  min-height: 100vh;
  background: #fff;

  .nav-bar {
    display: flex;
    align-items: center;
    height: 88rpx;
    padding: 0 30rpx;
    background: #fff;
    position: fixed;
    top: var(--status-bar-height);
    left: 0;
    right: 0;
    z-index: 100;

    .left {
      width: 60rpx;
      height: 88rpx;
      display: flex;
      align-items: center;
      
      .iconfont {
        font-size: 40rpx;
        color: #333;
      }
    }

    .title {
      flex: 1;
      text-align: center;
      font-size: 34rpx;
      font-weight: 500;
      color: #333;
    }

    .right {
      display: flex;
      align-items: center;
      gap: 30rpx;
      
      .iconfont {
        font-size: 40rpx;
        color: #333;
      }
    }
  }

  .collect-list {
    margin-top: calc(88rpx + var(--status-bar-height));
    margin-bottom: 100rpx;
    height: calc(100vh - 188rpx - var(--status-bar-height));
    box-sizing: border-box;
    padding: 30rpx;

    .collect-header {
      display: flex;
      justify-content: space-between;
      align-items: center;
      margin-bottom: 30rpx;

      .count {
        font-size: 28rpx;
        color: #999;
      }

      .create-btn {
        display: flex;
        align-items: center;
        height: 56rpx;
        padding: 0 24rpx;
        background: #8c2bff;
        border-radius: 28rpx;
        color: #fff;
        font-size: 28rpx;

        .plus {
          margin-right: 8rpx;
          font-size: 32rpx;
        }
      }
    }

    .folder-list {
      .folder-item {
        display: flex;
        align-items: center;
        padding: 20rpx 0;
        border-bottom: 1rpx solid #f5f5f5;

        .folder-image {
          width: 120rpx;
          height: 120rpx;
          border-radius: 12rpx;
          margin-right: 20rpx;
          background: #f5f5f5;
        }

        .folder-info {
          flex: 1;
          display: flex;
          flex-direction: column;
          justify-content: space-between;
          height: 100rpx;

          .folder-title {
            font-size: 32rpx;
            color: #333;
            font-weight: 500;
          }

          .folder-count {
            font-size: 26rpx;
            color: #999;
          }
        }

        &:active {
          background: #fafafa;
        }
      }
    }
  }

  .tab-bar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 100rpx;
    background: #fff;
    display: flex;
    align-items: center;
    border-top: 1rpx solid #f5f5f5;
    padding-bottom: env(safe-area-inset-bottom);

    .tab-item {
      flex: 1;
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
      color: #999;

      &.active {
        color: #8c2bff;
      }

      .tab-icon {
        width: 48rpx;
        height: 48rpx;
        margin-bottom: 6rpx;
      }

      .tab-text {
        font-size: 24rpx;
      }
    }
  }

  .create-dialog {
    width: 600rpx;
    background: #fff;
    border-radius: 16rpx;
    overflow: hidden;

    .dialog-header {
      padding: 30rpx;
      text-align: center;
      font-size: 32rpx;
      font-weight: 500;
      color: #333;
      border-bottom: 1rpx solid #f5f5f5;
    }

    .dialog-content {
      padding: 30rpx;

      input {
        width: 100%;
        height: 80rpx;
        border: 1rpx solid #eee;
        border-radius: 8rpx;
        padding: 0 20rpx;
        font-size: 28rpx;
        box-sizing: border-box;

        &:focus {
          border-color: #8c2bff;
        }
      }
    }

    .dialog-footer {
      display: flex;
      border-top: 1rpx solid #f5f5f5;

      button {
        flex: 1;
        height: 88rpx;
        line-height: 88rpx;
        text-align: center;
        font-size: 30rpx;
        border-radius: 0;
        margin: 0;

        &::after {
          border: none;
        }

        &.cancel-btn {
          background: #f5f5f5;
          color: #666;
        }

        &.confirm-btn {
          background: #8c2bff;
          color: #fff;

          &:active {
            opacity: 0.9;
          }
        }
      }
    }
  }
}
</style>